# 9.4 Advanced Usage
In addition to scheduling Java classes that implement the Runnable
interface, you can also directly schedule external applications, such as a specific executable program under Windows or Linux. Below is a code example:
String[] command = { "C:\\tomcat\\bin\\catalina.bat", "start" };
String[] envs = { "CATALINA_HOME=C:\\tomcat", "JAVA_HOME=C:\\jdks\\jdk5" };
File directory = new File("C:\\MyDirectory");
ProcessTask task = new ProcessTask(command, envs, directory);
cron4jPlugin.addTask(task);
me.add(cron4jPlugin);
1
2
3
4
5
6
7
2
3
4
5
6
7
As shown above, you only need to create a ProcessTask
object and point it to a specific application. Then, by adding it via addTask
, you can schedule it. This approach makes implementing functionalities like backing up the server database and zipping it into a ZIP file every midnight extremely simple and convenient. For more detailed usage, you can refer to the comments in the Cron4jPlugin.java
source code.